/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.lidovky.articles.domain;

import java.util.ArrayList;
import java.util.List;
import org.joda.time.LocalDate;

/**
 *
 * @author Martin Řehánek (rehan@mzk.cz)
 */
public class Article {

    private int lineNumber; //testovaci
    private int id;
    private Genre genre; //povinne
    //private String author; //povinne
    private Author author;
    private String title; //povinne
    private String subTitle;
    private String info;
    private String note;
    private Language language;
    private List<ArticleComponent> articleComponents;

    /**
     * @return the genre
     */
    public Genre getGenre() {
        return genre;
    }

    /**
     * @param genre the genre to set
     */
    public void setGenre(Genre genre) {
        this.genre = genre;
    }

    /**
     * @return the author
     */
    public Author getAuthor() {
        return author;
    }

    /**
     * @param author the author to set
     */
    public void setAuthor(Author author) {
        this.author = author;
    }

    /**
     * @return the info
     */
    public String getInfo() {
        return info;
    }

    /**
     * @param info the info to set
     */
    public void setInfo(String info) {
        this.info = info;
    }

    /**
     * @return the lineNumber
     */
    public int getLineNumber() {
        return lineNumber;
    }

    /**
     * @param lineNumber the lineNumber to set
     */
    public void setLineNumber(int lineNumber) {
        this.lineNumber = lineNumber;
    }

    /**
     * @return the articleComponents
     */
    public List<ArticleComponent> getArticleComponents() {
        return articleComponents;
    }

    /**
     * @param articleComponents the articleComponents to set
     */
    public void setArticleComponents(List<ArticleComponent> articleComponents) {
        this.articleComponents = articleComponents;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the subTitle
     */
    public String getSubTitle() {
        return subTitle;
    }

    /**
     * @param subTitle the subTitle to set
     */
    public void setSubTitle(String subTitle) {
        this.subTitle = subTitle;
    }

    public static Article getTestInstance() {
        int lineNumber = 0;
        Article article = new Article();
        article.setAuthor(new Author("Martin Rehanek", lineNumber));
        article.setGenre(Genre.ART);
        article.setLanguage(Language.cz);
        article.setInfo("testovaci clanek");
        article.setLineNumber(lineNumber);
        article.setSubTitle("Digitalni knihovny v CR");
        article.setTitle("Kramerius 4 a Fedora");
        List<ArticleComponent> parts = new ArrayList<ArticleComponent>();
        Issue issue1 = Issue.instanceOf(203, new LocalDate(1915, 7, 30), DayTime.morning, false, 0);
        ArticleComponent part1 = ArticleComponent.instanceOf(23, issue1, new NumberInterval(2, 3));
        parts.add(part1);
        Issue issue2 = Issue.instanceOf(204, new LocalDate(1915, 7, 31), DayTime.morning, false, 0);
        ArticleComponent part2 = ArticleComponent.instanceOf(23, issue2, new NumberInterval(2, 3));
        parts.add(part2);
        Issue issue3 = Issue.instanceOf(205, new LocalDate(1915, 8, 1), DayTime.morning, false, 0);
        ArticleComponent part3 = ArticleComponent.instanceOf(23, issue3, new NumberInterval(2, 3));
        parts.add(part3);
        article.setArticleComponents(parts);
        return article;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("author: ");
        builder.append(author);
        builder.append('\n');
        builder.append("title: ");
        builder.append(title);
        builder.append('\n');
        builder.append("subtitle: ");
        builder.append(subTitle);
        builder.append('\n');
        builder.append("genre: ");
        builder.append(genre);
        builder.append('\n');
        builder.append("info: ");
        builder.append(info);
        builder.append('\n');
        builder.append("consists of parts:");
        builder.append(articleComponents.size());
        builder.append('\n');
        return builder.toString();
    }

    /**
     * @return the note
     */
    public String getNote() {
        return note;
    }

    /**
     * @param note the note to set
     */
    public void setNote(String note) {
        this.note = note;
    }

    /**
     * @return the language
     */
    public Language getLanguage() {
        return language;
    }

    /**
     * @param language the language to set
     */
    public void setLanguage(Language language) {
        this.language = language;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    public int totalPages() {
        int result = 0;
        for (ArticleComponent comp : articleComponents) {
            result += comp.getPageInterval().size();
        }
        return result;
    }
}
